#include "DisplayTask.h" 

//extern xtime alarm_time;
//extern int alarmType=0;
                                                  
__task void TaskScan7Segment (void){
    xtime cur_time = RTCGetTime();
    int temp[4],j;
    while(1) {  
        cur_time = RTCGetTime();
        temp[3]=cur_time.jam/10;
        temp[2]=cur_time.jam%10;
        temp[1]=cur_time.menit/10;
        temp[0]=cur_time.menit%10;

        for(j=3;j>=0;j--){
    	    close_seven_segment();
            show_seven_segment(j,temp[j]);
            os_dly_wait(5);
        }
	}
}
__task void TaskRunningLED (void){
    int i;

    DrvGPIO_Open(E_GPC, 15, E_IO_OUTPUT);
    DrvGPIO_Open(E_GPC, 14, E_IO_OUTPUT);
    DrvGPIO_Open(E_GPC, 13, E_IO_OUTPUT);
    DrvGPIO_Open(E_GPC, 12, E_IO_OUTPUT);

    // interval 1000 ms    
    os_itv_set(250);
    while(1){
        
        for(i=12;i<16;i++){
            DrvGPIO_ClrBit(E_GPC, i);
            os_itv_wait();
            DrvGPIO_SetBit(E_GPC, i);
        }
    }
}

__task void TaskUpdateLCD (void){
    xtime cur_time = RTCGetTime();
    PrintClockString(cur_time);
    PrintDateString(cur_time);

    // interval 1000 ms    
    os_itv_set(1000);
    while(1){
        os_itv_wait();
        cur_time = RTCGetTime();
        PrintClockString(cur_time);
        if(!(cur_time.jam|cur_time.menit|cur_time.detik)){
            PrintDateString(cur_time); 
            //hanya update saat 00:00:00
        }
    }
}
